import userStroe from '@/plugins/pinia/stores/user';
import type { App } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';
import setupGurad from './guard';
import routes from './routes/index';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

export async function setupRouter(app: App) {
  // 初始化时，获取用户信息
  const user = userStroe();
  await user.getUserInfo();

  setupGurad(router);
  app.use(router);
}

export default router;
